﻿alert(11111);
var rowsPerPage = 10;
var totalRows = 0;
var arrUsers = [];

function initListUser() {
    rowsPerPage = $("#drpNumPage").val();
    Doctors_WebForum.Admin.UIControls.Accounts.GetAllUser(function (users) {
        lstFuncs = users.value;alert(users.value);
        arrUsers = lstFuncs;
        totalRows = dataLength = lstFuncs.length;
        if (dataLength > 0) {
            LoadFunctionOfPage(1, lstFuncs);
        } else {
            util.removeAllRows("functionGird", { filter: function (tr) { return (tr.id != "funcTemp"); } }); //xoa Grid chi trua template
            $("#trNoReSult").attr('style', 'display:');
            $("#divPaging").attr('style', 'display:none');
        }
    });
}
function LoadFunctionOfPage(pageCurrent, users) {
    var object = null;
    rowsPerPage = $("#drpNumPage").val();
    dataLength = users.length;
    vfrom = (pageCurrent - 1) * rowsPerPage;
    var id = 0;
    var row = 0;
    var css = '';
    util.removeAllRows("functionGird", { filter: function (tr) { return (tr.id != "funcTemp"); } });
    $("#trNoReSult").attr('style', 'display:none');
    $("#chkAll").attr("checked", 0);
    for (var i = 0; i < rowsPerPage; i++) {
        if ((vfrom + i) < dataLength) {
            object = users[vfrom + i];
            id = object.UserID;
            css = (i % 2 == 0) ? 'Row_Odd' : 'Row_Round';

            util.cloneNode("funcTemp", { idSuffix: id });

            $("#tdUsername" + id).html(object.UserName);
            $("#tdEmail" + id).html(object.Email);
            $("#tdLastLogin" + id).html(object.StrLastLogin);
            $("#tdCreateDate" + id).html(object.StrCreatedDate);
            $("#tdIsActive" + id).html(object.Active);
            $("#tdRoleName" + id).html(object.RoleName);
            $("#tdIsBan" + id).html(object.Ban);

            $("#chk" + id).attr("checked", 0);
            $("#funcTemp" + id).attr('style', 'display:');
            $("#funcTemp" + id).attr('class', css);
        }
    }
    initPaging("divPaging", dataLength, "gotoPage", 1);
}

//================================================================================================

function initPagingSearch(divPage, totalRowsSearch, functionName, currentPage) {
    $("#" + divPage).html(callPage(currentPage, 1, totalRowsSearch, rowsPerPage, functionName));
    $("#" + divPage).attr('style', 'display:');
}

//================================================================================================
//Ham phuc vu phan trang cho danh sach user
function initPaging(divPage, totalRows, functionName, currentPage) {
    $("#" + divPage).html(callPage(currentPage, 1, totalRows, rowsPerPage, functionName));
    $("#" + divPage).attr('style', 'display:');
}
function gotoPage(pageCurrent, base, functionName) {
    LoadFunctionOfPage(pageCurrent, arrUsers);
    callJumpPage("divPaging", pageCurrent, base, functionName);
}
function callJumpPage(divPage, pageCurrent, base, functionName) {
    pt = callPage(pageCurrent, base, totalRows, rowsPerPage, functionName);
    $("#" + divPage).html(pt);
    $("#" + divPage).attr('style', 'display:');
}

function DrpChange() {
    initListUser();
}

function Functon_Edit(id) {
    alert(id);
}
function Functon_Del() {
    var listIDs = getChecked("chkFunction", 3);
    if (listIDs == "") {
        alert(msgNocheck);
        return;
    }
alert(listIDs);
    if (confirm("Ban co that su muon xoa cai nay?")) {
        Doctors_WebForum.Admin.UIControls.Accounts.Delete(listIDs, function (bResult) {
            if (bResult.value) {
                ShowMessage("divFuncMess", "tdMessage", msgDel);
                initListUser();
            } else {
                ShowMessage("divFuncMess", "tdMessage", msgDelErr);
            }
        });
    }
}
function Functon_Ban(id) {

}